﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZG_member.BLL;
using System.Configuration;

namespace ZG_member
{
    public partial class RollinfoAdd : Form
    {
        
        RollInfo inf;
        public RollinfoAdd(RollInfo info1)
        {
            InitializeComponent();
            inf = info1;
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];
            this.Opacity = 0;
        }

       
           
            
     
       
        /// <summary>
        /// 添加和修改角色
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnroleName_Click(object sender, EventArgs e)
        {
            if (txtroleName.Text == string.Empty)
            {
                MessageBox.Show("角色名不能为空");
                return;
            }
            roleInfo info=new roleInfo ();
            Model.roleInfo infoMod = new Model.roleInfo();
            if (this.Text == "修改角色")
            {

                infoMod = info.GetModelList("id='" +inf.ID  + "'")[0];
            }
            infoMod.roleName = txtroleName.Text.Trim();
            StringBuilder sb = new StringBuilder();
            //会员管理中心
            foreach (CheckBox c in groupBox1.Controls)
            {
                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            //基本设置
            foreach (CheckBox c in groupBox2.Controls)
            {
                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            //系统设置
            foreach (CheckBox c in groupBox3.Controls)
            {

                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            //查询图表
            foreach (CheckBox c in groupBox4.Controls)
            {
                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            //收入明细
            foreach (CheckBox c in groupBox5.Controls)
            {
                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            infoMod.roleInfo1 = sb.ToString();
            if (this.Text == "修改角色")
            {
                //修改角色
                if (info.Update(infoMod))
                {
                    MessageBox.Show("修改成功");
                    inf.dgvroleInfoBind();
                    this.Close();
                }
            }
            else
            {
                //添加角色
                int row = info.Add(infoMod);
                if (row > 0)
                {
                    MessageBox.Show("添加成功");
                    inf.dgvroleInfoBind();
                }
            }
        }

        private void RollinfoAdd_Load(object sender, EventArgs e)
        {
            this.timer1.Start();
            if (inf.ID != 0)
            {
                this.Text = "修改角色";
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.timer2.Start();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer1.Stop();

            }

        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();
            }
        }
        int flag = 0;
        private void RollinfoAdd_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (flag == 0)
            {
                e.Cancel = true;
                flag = 1;
                this.timer2.Start();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtroleName.Text == string.Empty)
            {
                MessageBox.Show("角色名不能为空");
                return;
            }
            roleInfo info = new roleInfo();
            Model.roleInfo infoMod = new Model.roleInfo();
            if (this.Text == "修改角色")
            {

                infoMod = info.GetModelList("id='" + inf.ID + "'")[0];
            }
            infoMod.roleName = txtroleName.Text.Trim();
            StringBuilder sb = new StringBuilder();
            foreach (CheckBox c in groupBox1.Controls)
            {
                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            foreach (CheckBox c in groupBox2.Controls)
            {
                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            foreach (CheckBox c in groupBox3.Controls)
            {

                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            foreach (CheckBox c in groupBox4.Controls)
            {
                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            foreach (CheckBox c in groupBox5.Controls)
            {
                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            foreach (CheckBox c in groupBox6.Controls)
            {
                if (c is CheckBox)
                {
                    if (((CheckBox)c).Checked == true)
                    {
                        sb.Append("1");
                    }
                    else
                    {
                        sb.Append("0");
                    }
                }
            }
            infoMod.roleInfo1 = sb.ToString();
            if (this.Text == "修改角色")
            {
                if (info.Update(infoMod))
                {
                    MessageBox.Show("修改成功");
                    inf.dgvroleInfoBind();
                    this.Close();
                }
            }
            else
            {
                int row = info.Add(infoMod);
                if (row > 0)
                {
                    MessageBox.Show("添加成功");
                    inf.dgvroleInfoBind();
                    this.Close();
                }
            }
        }

        private void tianjiahuiyuan_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void xitongrizhi_CheckedChanged(object sender, EventArgs e)
        {

        }
    }
}
